import json
import time
import re
from .gegtPublicData import *

def getSquareData():
    cars = list(getAllCars())
    carsVolume = {}
    for car in cars:
        if carsVolume.get(car.seriesName, -1) == -1:
            carsVolume[car.seriesName] = int(car.sale)
        else:
            carsVolume[car.seriesName] += int(car.sale)
    carsVolume = sorted(carsVolume.items(), key=lambda x: x[1], reverse=True)[:15]
    # print(carsVolume)
    brandList = []
    saleList = []
    priceList = []
    for i in carsVolume:
        brandList.append(i[0])
        saleList.append(i[1])
    for j in cars[:15]:     ##无法转换数据库内的 []  符号，故使用正则表达式
        j.price = re.findall('\d+\.\d+', j.price)     ##只匹配数字，忽略符号
        j.price = j.price[0]
        priceList.append(float(j.price))
        # priceList.append(i[2])
    return brandList, saleList, priceList